package com.fdb.efp.loan.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.loan.service.domain.DwBaiduLedgerTemp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.fdb.efp.loan.service.dao.DwBaiduLedgerTempDao;
import com.fdb.efp.loan.service.facade.DwBaiduLedgerTempService;
import com.fdb.efp.loan.service.vo.DwBaiduLedgerTempVO;

/**
 * Service Impl: 并账文件信息临时表服务实现
 * 
 * @author ligm
 * @date 2019-05-06
 */
@Service("dwBaiduLedgerTempService")
public class DwBaiduLedgerTempServiceImpl implements DwBaiduLedgerTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(DwBaiduLedgerTempServiceImpl.class);

	@Autowired
	private DwBaiduLedgerTempDao dwBaiduLedgerTempDao;

	/**
	 * 新增数据
	 * 
	 * @param inDwBaiduLedgerTempVo
	 * @return
	 */
	public int insertDwBaiduLedgerTemp(DwBaiduLedgerTempVO inDwBaiduLedgerTempVo) {
		logger.debug("当前新增数据为:" + inDwBaiduLedgerTempVo.toString());
		int num = 0;
		try {
			DwBaiduLedgerTemp dwBaiduLedgerTemp = new DwBaiduLedgerTemp();
			beanCopy(inDwBaiduLedgerTempVo, dwBaiduLedgerTemp);
			num = dwBaiduLedgerTempDao.insertDwBaiduLedgerTemp(dwBaiduLedgerTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 根据主键删除信息
	 * 
	 * @param inDwBaiduLedgerTempVo
	 * @return
	 */
	public int deleteByPk(DwBaiduLedgerTempVO inDwBaiduLedgerTempVo) {
		logger.debug("当前删除数据条件为:" + inDwBaiduLedgerTempVo);
		int num = 0;
		try {
			DwBaiduLedgerTemp dwBaiduLedgerTemp = new DwBaiduLedgerTemp();
			beanCopy(inDwBaiduLedgerTempVo, dwBaiduLedgerTemp);
			num = dwBaiduLedgerTempDao.deleteByPk(dwBaiduLedgerTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inDwBaiduLedgerTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键更新信息
	 * 
	 * @param inDwBaiduLedgerTempVo
	 * @return
	 */
	public int updateByPk(DwBaiduLedgerTempVO inDwBaiduLedgerTempVo) {
		logger.debug("当前修改数据为:" + inDwBaiduLedgerTempVo.toString());
		int num = 0;
		try {
			DwBaiduLedgerTemp dwBaiduLedgerTemp = new DwBaiduLedgerTemp();
			beanCopy(inDwBaiduLedgerTempVo, dwBaiduLedgerTemp);
			num = dwBaiduLedgerTempDao.updateByPk(dwBaiduLedgerTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inDwBaiduLedgerTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键查询详情
	 * 
	 * @param dwBaiduLedgerTemp
	 * @return
	 */
	public DwBaiduLedgerTempVO queryByPk(DwBaiduLedgerTempVO inDwBaiduLedgerTempVo) {

		logger.debug("当前查询参数信息为:" + inDwBaiduLedgerTempVo);
		try {
			DwBaiduLedgerTemp queryDwBaiduLedgerTemp = new DwBaiduLedgerTemp();
			beanCopy(inDwBaiduLedgerTempVo, queryDwBaiduLedgerTemp);
			DwBaiduLedgerTemp queryRslDwBaiduLedgerTemp = dwBaiduLedgerTempDao.queryByPk(queryDwBaiduLedgerTemp);
			if (Objects.nonNull(queryRslDwBaiduLedgerTemp)) {
				DwBaiduLedgerTempVO outDwBaiduLedgerTempVo = beanCopy(queryRslDwBaiduLedgerTemp, new DwBaiduLedgerTempVO());
				logger.debug("当前查询结果为:" + outDwBaiduLedgerTempVo.toString());
				return outDwBaiduLedgerTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 一级数据权限
	 * 
	 * @param dwBaiduLedgerTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLedgerTempVO> queryAllByLevelOne(DwBaiduLedgerTempVO dwBaiduLedgerTempVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<DwBaiduLedgerTempVO> list = null;
		try {
			List<DwBaiduLedgerTemp> dwBaiduLedgerTemps = dwBaiduLedgerTempDao.queryAllByLevelOneByPage(dwBaiduLedgerTempVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:" + dwBaiduLedgerTemps.size());
			pageSet(dwBaiduLedgerTemps, dwBaiduLedgerTempVo);
			list = (List<DwBaiduLedgerTempVO>) beansCopy(dwBaiduLedgerTemps, DwBaiduLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 二级数据权限
	 * 
	 * @param dwBaiduLedgerTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLedgerTempVO> queryAllByLevelTwo(DwBaiduLedgerTempVO dwBaiduLedgerTempVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<DwBaiduLedgerTemp> dwBaiduLedgerTemps = dwBaiduLedgerTempDao.queryAllByLevelTwoByPage(dwBaiduLedgerTempVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:" + dwBaiduLedgerTemps.size());
		List<DwBaiduLedgerTempVO> list = null;
		try {
			pageSet(dwBaiduLedgerTemps, dwBaiduLedgerTempVo);
			list = (List<DwBaiduLedgerTempVO>) beansCopy(dwBaiduLedgerTemps, DwBaiduLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 三级数据权限
	 * 
	 * @param dwBaiduLedgerTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLedgerTempVO> queryAllByLevelThree(DwBaiduLedgerTempVO dwBaiduLedgerTempVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<DwBaiduLedgerTemp> dwBaiduLedgerTemps = dwBaiduLedgerTempDao.queryAllByLevelThreeByPage(dwBaiduLedgerTempVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:" + dwBaiduLedgerTemps.size());
		List<DwBaiduLedgerTempVO> list = null;
		try {
			pageSet(dwBaiduLedgerTemps, dwBaiduLedgerTempVo);
			list = (List<DwBaiduLedgerTempVO>) beansCopy(dwBaiduLedgerTemps, DwBaiduLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 四级数据权限
	 * 
	 * @param dwBaiduLedgerTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLedgerTempVO> queryAllByLevelFour(DwBaiduLedgerTempVO dwBaiduLedgerTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduLedgerTemp> dwBaiduLedgerTemps = dwBaiduLedgerTempDao.queryAllByLevelFourByPage(dwBaiduLedgerTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + dwBaiduLedgerTemps.size());
		List<DwBaiduLedgerTempVO> list = null;
		try {
			pageSet(dwBaiduLedgerTemps, dwBaiduLedgerTempVo);
			list = (List<DwBaiduLedgerTempVO>) beansCopy(dwBaiduLedgerTemps, DwBaiduLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 五级数据权限
	 * 
	 * @param dwBaiduLedgerTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLedgerTempVO> queryAllByLevelFive(DwBaiduLedgerTempVO dwBaiduLedgerTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduLedgerTemp> dwBaiduLedgerTemps = dwBaiduLedgerTempDao.queryAllByLevelFiveByPage(dwBaiduLedgerTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + dwBaiduLedgerTemps.size());
		List<DwBaiduLedgerTempVO> list = null;
		try {
			pageSet(dwBaiduLedgerTemps, dwBaiduLedgerTempVo);
			list = (List<DwBaiduLedgerTempVO>) beansCopy(dwBaiduLedgerTemps, DwBaiduLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 
	 * 统计【并账文件信息临时表】数据量 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:10:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:10
	 * @date 2019年3月23日 下午12:11:10
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【并账文件信息临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = dwBaiduLedgerTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【并账文件信息临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
